import { prop, modelOptions } from '@typegoose/typegoose'
import { ApiProperty } from '@nestjs/swagger'
import { hashSync } from 'bcryptjs'


@modelOptions({
    schemaOptions: {
        timestamps: true
    }
})
export class User {
    @ApiProperty({
        description: '用户名',
        example: 'user1'
    })
    @prop()
    username: string

    @ApiProperty({
        description: '密码',
        example: 'pass1'
    })
    @prop({
        select: false, // 在常规请求中不显示该字段
        get(v) {
            return v
        },
        // 对密码进行加密操作
        set(v) {
            return v ? hashSync(v) : v
        }
    })
    password: string


}